﻿using System;
using System.Windows;
using HomeService.Models;
using Microsoft.Win32;

namespace HomeService.Views
{
    public partial class AddPhotosView
    {
        public AddPhotosView()
        {
            InitializeComponent();
        }

        private void OpenImage(object sender, RoutedEventArgs e)
        {
            var openFileDialog = new OpenFileDialog {
                InitialDirectory = "c:\\",
                Filter = "JPEG and PNG files (*.jpg, *.jpeg, *.png)|*.jpg;*.jpeg;*.png"
            };

            if (openFileDialog.ShowDialog() == true) {
                try {
                    var fileStream = openFileDialog.OpenFile();
                    var serviceRequest = DataContext as ServiceRequest;
                    if (serviceRequest == null) return;
                    serviceRequest.AddPhoto(fileStream);
                } catch (ValidationException ex) {
                    MessageBox.Show(ex.Message);
                } catch (Exception) {
                    MessageBox.Show("Tiedoston avaaminen epäonnistui");
                }
            }
        }
    }
}